import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'index',
    redirect:'/home'
  },
  {
    path:"/login",name:'login',component:()=>import('../views/loginView.vue')
  },

    { path:"/sj",name:'sj',component:()=>import('../components/backend/siji/siji.vue')},
    { path:"/huoy",name:'huoy',component:()=>import('../components/backend/siji/huoy.vue')},
    { path:"/sjrz",name:'sjrz',component:()=>import('../components/backend/siji/sjrz.vue')},
    { path:"/wdcl",name:'wdcl',component:()=>import('../components/backend/siji/wdcl.vue')},
    { path:"/wdrw",name:'wdrw',component:()=>import('../components/backend/siji/wdrw.vue')},
    { path:"/smyz",name:'smyz',component:()=>import('../components/backend/siji/smyz.vue')},

  {
    path:"/wlym",name:'wlym',component:()=>import('../components/backend/yonghu/wlym.vue')
  },
  //用户(客户端)
  {path: '/wljij', name: 'wljij', component: () => import('../components/backend/yonghu/wljij.vue')},
  {path: '/wljid', name: 'wljid', component: () => import('../components/backend/yonghu/wljid.vue')},
  //快递员端
  {path: '/kdypickup', name: 'sj', component: () => import('../components/backend/kuaidiyuan/pick-up.vue')}, //(取件)首页可跳转追踪
  {path: '/kdysend', name: 'kdysend', component: () => import('../components/backend/kuaidiyuan/send.vue')}, //快递派送 
  {path: '/kdycomputation', name: 'computation', component: () => import('../components/backend/kuaidiyuan/computation.vue')}, //查看货物是否填写进行计量 
  {path: '/kdyworkingRange', name: 'workingRange', component: () => import('../components/backend/kuaidiyuan/workingRange.vue')}, //取派件工作范围 
  {path: '/kdyinformation', name: 'information', component: () => import('../components/backend/kuaidiyuan/information.vue')}, //快递员个人信息 

  {
    path: '/home',
    name: 'home',
    component: () => import('../views/HomeView.vue'),
    // redirect:'/home/workbench', View the transport task details
    children:[
      //蒋萍香
      {path: 'first', component: ()=> import('../views/FirstView.vue')},
      {path:'jigoshujukanban',name:'jigoshujukanban',component:()=>import('../components/backend/jiangpingxiang/yunshuguanli/jigoshujukanban.vue')},
      {path:'Driver_work_list_management',name:'Driver_work_list_management',component:()=>import('../components/backend/jiangpingxiang/yunshuguanli/Driver_work_list_managementView.vue')},
      {path:'Transportation_task_Management',name:'Transportation_task_Management',component:()=>import('../components/backend/jiangpingxiang/yunshuguanli/Transportation_task_ManagementView.vue')},
      {path:'View_the_transport_task_details',name:'View_the_transport_task_details',component:()=>import('../components/backend/jiangpingxiang/yunshuguanli/View_the_transport_task_detailsView.vue')},
      {path:'Transportation_Management_END',name:'Transportation_Management_END',component:()=>import('../components/backend/jiangpingxiang/yunshuguanli/Transportation_Management_ENDView.vue')},
      //刘成杰的机构作业
      {path:'jigozuoyefanwei',name:'jigozuoyefanwei',component:()=>import('../components/backend/liuchengjie/JiGoZuoYe/jigozuoyefanwei.vue')},
      //刘成杰的转运中心
      {path:'chedui',name:'chedui',component:()=>import('../components/backend/liuchengjie/zhuanyunzhongxin/chedui.vue')},
      {path:'chexingguanli',name:'chexingguanli',component:()=>import('../components/backend/liuchengjie/zhuanyunzhongxin/chexingguanli.vue')},
      {path:'sijiguanli',name:'sijiguanli',component:()=>import('../components/backend/liuchengjie/zhuanyunzhongxin/sijiguanli.vue')},
      {path:'xianluguanli',name:'xianluguanli',component:()=>import('../components/backend/liuchengjie/zhuanyunzhongxin/xianluguanli.vue')},
      {path:'xianluTypeguanli',name:'xianluTypeguanli',component:()=>import('../components/backend/liuchengjie/zhuanyunzhongxin/xianluTypeguanli.vue')},
      {path:'cheliangguanli',name:'cheliangguanli',component:()=>import('../components/backend/liuchengjie/zhuanyunzhongxin/cheliangguanli.vue')},
      //罗庆调度
      {path:'diaoduxinxi',name:'diaoduxinxi',component:()=>import('../components/backend/luoqing/diaoduguanli/diaoduxinxi.vue')},
      {path:'zhinengdiaodu',name:'zhinengdiaodu',component:()=>import('../components/backend/luoqing/diaoduguanli/zhinengdiaodu.vue')},
      //订单管理
      {path:'dingdanliebiao',name:'dingdanliebiao',component:()=>import('../components/backend/luoqing/dingdanguanli/dingdanliebiao.vue')},
      //用户订单管理
      {path:'yonghudingdanguanli',name:'dingdanliebiao',component:()=>import('../components/backend/luoqing/yonghudingdanguanl/yonghudingdanguanli.vue')},
      //网点管理
      {path:'huopinguanli',name:'huopinguanli',component:()=>import('../components/backend/luoqing/wangdianguanli/huopinguanli.vue')},
      {path:'kuaidizuoyefanweiguanli',name:'kuaidizuoyefanweiguanli',component:()=>import('../components/backend/luoqing/wangdianguanli/kuaidizuoyefanweiguanli.vue')},
      {path:'kuaidizuoyeguanli',name:'kuaidizuoyeguanli',component:()=>import('../components/backend/luoqing/wangdianguanli/kuaidizuoyeguanli.vue')},
      //运单管理
      {path:'yundanliebiao',name:'yundanliebiao',component:()=>import('../components/backend/luoqing/yundanguanli/yundanliebiao.vue')},
      //唐丽超组织管理
      {path:'zuzhiguanli',name:'zuzhiguanli',component:()=>import('../components/backend/tanglichao/zuzhiguanli.vue')},
      //前端页面
      {path:'shoym',name:'shoym',component:()=>import('../components/backend/tanglichao/shoym.vue')},
      //系统管理
      {path:'caidanguanli',name:'caidanguanli',component:()=>import('../components/backend/xiaoshuguang/caidanguanli.vue')},
      {path:'gangweiguanli',name:'gangweiguanli',component:()=>import('../components/backend/xiaoshuguang/gangweiguanli.vue')},
      {path:'jueseguanli',name:'jueseguanli',component:()=>import('../components/backend/xiaoshuguang/jueseguanli.vue')},
      {path:'User',name:'User',component:()=>import('../components/backend/xiaoshuguang/User.vue')},
      {path:'wenjianguanli',name:'wenjianguanli',component:()=>import('../components/backend/xiaoshuguang/wenjianguanli.vue')},
      //日志
      {path:'caozuorizhi',name:'caozuorizhi',component:()=>import('../components/backend/rizhi/caozuorizhi.vue')},
      {path:'Loginrizhi',name:'Loginrizhi',component:()=>import('../components/backend/rizhi/Loginrizhi.vue')},
     ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})


router.beforeEach((to,from,next)=>{
  let userInfo =  sessionStorage.getItem("user")
  if(!userInfo){
    if(to.path==="/" || to.path==="/login"){
      next()
    }else{
      next({path:'/login'})
    }
  }else{
    next()
  }  
})

//路由后置守卫
router.afterEach((to)=>{
  let menpath=[]
  //如果breadcrunmbName是空的就不需要传递参数
  if(!to.query.breadcrunmbName){
    //调用getbreadcrunmbName方法
    router.app.$store.commit("getbreadcrunmbName")
    //如果不是空
  }else if(to.query.breadcrunmbName.length!=0){
    //根据逗号分割参数
    menpath = to.query.breadcrunmbName.split(",")
    //调用getbreadcrunmbName传参
    router.app.$store.commit("getbreadcrunmbName",menpath)
  }

})

export default router
